home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Graphics / FlashMandel / Sources / FlashMandelPPC_PPC.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-20  |  9.7 KB  |  341 lines

  1. #include <exec/types.h>
  2. #include <math.h>
  3.  
  4. #include "flashmandel.h"
  5.  
  6. void SAVEDS CalcFractalPPC (struct MandelChunk *,UBYTE *);
  7.  
  8. UBYTE LinearRemapPPC     (const LDouble,const LDouble,const LDouble);
  9. UBYTE LogRemapPPC        (const LDouble,const LDouble,const LDouble);
  10. UBYTE RepeatedRemapPPC   (const LDouble,const LDouble,const LDouble);
  11. UBYTE SquareRootRemapPPC (const LDouble,const LDouble,const LDouble);
  12. UBYTE OneRemapPPC        (const LDouble,const LDouble,const LDouble);
  13. UBYTE TwoRemapPPC        (const LDouble,const LDouble,const LDouble);
  14. UBYTE ThreeRemapPPC      (const LDouble,const LDouble,const LDouble);
  15. UBYTE FourRemapPPC       (const LDouble,const LDouble,const LDouble);
  16.  
  17. void JVLinePPC (struct MandelChunk *,UBYTE *,const LONG,const LONG,const LONG);
  18. void JHLinePPC (struct MandelChunk *,UBYTE *,const LONG,const LONG,const LONG);
  19. void MVLinePPC (struct MandelChunk *,UBYTE *,const LONG,const LONG,const LONG);
  20. void MHLinePPC (struct MandelChunk *,UBYTE *,const LONG,const LONG,const LONG);
  21.  
  22. BOOL CheckBoxPPC (UBYTE *,const LONG,const LONG,const LONG,const LONG);
  23. BOOL RectangleDrawPPC (struct MandelChunk *,UBYTE *,const LONG,const LONG,const LONG,const LONG);
  24.  
  25. IMPORT ULONG JuliaPPC  (ULONG,LDouble,LDouble,LDouble,LDouble);
  26. IMPORT ULONG MandelPPC (ULONG,LDouble,LDouble);
  27.  
  28. UBYTE (*COLORREMAP_PPC) (const LDouble,const LDouble,const LDouble);
  29. void  (*V_LINE_PPC)     (struct MandelChunk *,UBYTE *,const LONG,const LONG,const LONG);
  30. void  (*H_LINE_PPC)     (struct MandelChunk *,UBYTE *,const LONG,const LONG,const LONG);
  31.  
  32. ULONG MODULO_PPC;
  33.  
  34. ULONG ITERATIONS_PPC,COLORS_PPC;
  35.  
  36. LDouble INCREMREALPPC,INCREMIMAGPPC;
  37.  
  38. UBYTE LinearRemapPPC (const LDouble Iterations,const LDouble MaxColors,const LDouble MaxIterations)
  39. {
  40.   return ((UBYTE) floor ((Iterations * MaxColors) / MaxIterations));
  41. }
  42.  
  43. UBYTE LogRemapPPC (const LDouble Iterations,const LDouble MaxColors,const LDouble MaxIterations)
  44. {
  45.   return ((UBYTE) floor ((log (Iterations) * MaxColors) / log (MaxIterations)));
  46. }
  47.  
  48. UBYTE RepeatedRemapPPC (const LDouble Iterations,const LDouble MaxColors,const LDouble MaxIterations)
  49. {
  50.   return ((UBYTE) floor (MaxColors - fmod (MaxIterations-Iterations,MaxColors) - 1.0));
  51. }
  52.  
  53. UBYTE SquareRootRemapPPC (const LDouble Iterations,const LDouble MaxColors,const LDouble MaxIterations)
  54. {
  55.   return ((UBYTE) floor ((sqrt (Iterations) * MaxColors) / sqrt (MaxIterations)));
  56. }
  57.  
  58. UBYTE OneRemapPPC (const LDouble Iterations,const LDouble MaxColors,const LDouble MaxIterations)
  59. {
  60.   return ((UBYTE) floor (((Iterations * Iterations - Iterations) * MaxColors) / (MaxIterations * MaxIterations - MaxIterations)));
  61. }
  62.  
  63. UBYTE TwoRemapPPC (const LDouble Iterations,const LDouble MaxColors,const LDouble MaxIterations)
  64. {
  65.   return ((UBYTE) floor ((sqrt (pow (Iterations,3.0) - Iterations * Iterations - Iterations) * MaxColors) / sqrt (pow (MaxIterations,3.0) - MaxIterations * MaxIterations - MaxIterations)));
  66. }
  67.  
  68. UBYTE ThreeRemapPPC (const LDouble Iterations,const LDouble MaxColors,const LDouble MaxIterations)
  69. {
  70.   return ((UBYTE) floor ((sinh (log (pow (Iterations,3.0))) * MaxColors) / (sinh (log (pow (MaxIterations,3.0))))));
  71. }
  72.  
  73. UBYTE FourRemapPPC (const LDouble Iterations,const LDouble MaxColors,const LDouble MaxIterations)
  74. {
  75.   return ((UBYTE) floor ((cosh (log10 (pow (Iterations,3.0))) * MaxColors) / (cosh (log10 (pow (MaxIterations,3.0))))));
  76. }
  77.  
  78. void MVLinePPC (struct MandelChunk *MandelInfo,UBYTE *GfxMem,const LONG b1,const LONG b2,const LONG x)
  79. {
  80. REGISTER LONG y;
  81.  
  82. REGISTER ULONG Color;
  83.  
  84. REGISTER LDouble Cre,Cim;
  85.  
  86.  Cre = MandelInfo->RMin + (((LDouble)  x) * INCREMREALPPC);
  87.  
  88.  Cim = MandelInfo->IMax - (((LDouble) b2) * INCREMIMAGPPC);
  89.  
  90.  GfxMem += x * sizeof (*GfxMem);
  91.  
  92.  for (y = b2; y >= b1; y--)
  93.  {
  94.      Color = MandelPPC (ITERATIONS_PPC,Cre,Cim);
  95.  
  96.      if (Color) Color = COLORREMAP_PPC (Color,COLORS_PPC,ITERATIONS_PPC) + RESERVED_PENS;
  97.  
  98.      Cim += INCREMIMAGPPC;
  99.  
  100.      *(GfxMem + y * MODULO_PPC) = Color;
  101.  }
  102. }
  103.  
  104. void MHLinePPC (struct MandelChunk *MandelInfo,UBYTE *GfxMem,const LONG a1,const LONG a2,const LONG y)
  105. {
  106. REGISTER LONG x;
  107.  
  108. REGISTER ULONG Color;
  109.  
  110. REGISTER LDouble Cre,Cim;
  111.  
  112.  Cre = MandelInfo->RMin + (((LDouble) a1) * INCREMREALPPC);
  113.  
  114.  Cim = MandelInfo->IMax - (((LDouble)  y) * INCREMIMAGPPC);
  115.  
  116.  GfxMem += (y * MODULO_PPC) + a1;
  117.  
  118.  for (x = a2; x >= a1; x--)
  119.  {
  120.      Color = MandelPPC (ITERATIONS_PPC,Cre,Cim);
  121.  
  122.      if (Color) Color = COLORREMAP_PPC (Color,COLORS_PPC,ITERATIONS_PPC) + RESERVED_PENS;
  123.  
  124.      Cre += INCREMREALPPC;
  125.  
  126.      *GfxMem++ = Color;
  127.  }
  128. }
  129.  
  130. void JVLinePPC (struct MandelChunk *MandelInfo,UBYTE *GfxMem,const LONG b1,const LONG b2,const LONG x)
  131. {
  132. REGISTER LONG y;
  133.  
  134. REGISTER ULONG Color;
  135.  
  136. REGISTER LDouble Cre,Cim,JKre,JKim;
  137.  
  138.  Cre = MandelInfo->RMin + (((LDouble)  x) * INCREMREALPPC);
  139.  
  140.  Cim = MandelInfo->IMax - (((LDouble) b2) * INCREMIMAGPPC);
  141.  
  142.  JKre = MandelInfo->JKre;
  143.  
  144.  JKim = MandelInfo->JKim;
  145.  
  146.  GfxMem += x * sizeof (*GfxMem);
  147.  
  148.  for (y = b2; y >= b1; y--)
  149.  {
  150.      Color = JuliaPPC (ITERATIONS_PPC,Cre,Cim,JKre,JKim);
  151.  
  152.      if (Color) Color = COLORREMAP_PPC (Color,COLORS_PPC,ITERATIONS_PPC) + RESERVED_PENS;
  153.  
  154.      Cim += INCREMIMAGPPC;
  155.  
  156.      *(GfxMem + y * MODULO_PPC) = Color;
  157.  }
  158. }
  159.  
  160. void JHLinePPC (struct MandelChunk *MandelInfo,UBYTE *GfxMem,const LONG a1,const LONG a2,const LONG y)
  161. {
  162. REGISTER LONG x;
  163.  
  164. REGISTER ULONG Color;
  165.  
  166. REGISTER LDouble Cre,Cim,JKre,JKim;
  167.  
  168.  Cre = MandelInfo->RMin + (((LDouble) a1) * INCREMREALPPC);
  169.  
  170.  Cim = MandelInfo->IMax - (((LDouble)  y) * INCREMIMAGPPC);
  171.  
  172.  JKre = MandelInfo->JKre;
  173.  
  174.  JKim = MandelInfo->JKim;
  175.  
  176.  GfxMem += (y * MODULO_PPC) + a1;
  177.  
  178.  for (x = a1; x <= a2; x++)
  179.  {
  180.      Color = JuliaPPC (ITERATIONS_PPC,Cre,Cim,JKre,JKim);
  181.  
  182.      if (Color) Color = COLORREMAP_PPC (Color,COLORS_PPC,ITERATIONS_PPC) + RESERVED_PENS;
  183.  
  184.      Cre += INCREMREALPPC;
  185.  
  186.      *GfxMem++ = Color;
  187.  }
  188. }
  189.  
  190. BOOL CheckBoxPPC (UBYTE *GfxMem,const LONG a1,const LONG b1,const LONG a2,const LONG b2)
  191. {
  192. const UBYTE Color = *(GfxMem + b1 * MODULO_PPC + a1 * sizeof (*GfxMem));
  193.  
  194. UBYTE *Address_1,*Address_2;
  195.  
  196. REGISTER LONG Var;
  197.  
  198.   if (Color != *(GfxMem + b2 * MODULO_PPC + a2 * sizeof (*GfxMem))) return FALSE;
  199.  
  200.   if (Color != *(GfxMem + b1 * MODULO_PPC + a2 * sizeof (*GfxMem))) return FALSE;
  201.  
  202.   if (Color != *(GfxMem + b2 * MODULO_PPC + a1 * sizeof (*GfxMem))) return FALSE;
  203.  
  204.   Address_1 = GfxMem + b1 * MODULO_PPC + a1;
  205.  
  206.   Address_2 = GfxMem + b2 * MODULO_PPC + a1;
  207.  
  208.   for (Var = (a2 - 1L); Var > a1; Var--)
  209.   {
  210.       if (Color != *Address_1++) return FALSE;
  211.  
  212.       if (Color != *Address_2++) return FALSE;
  213.   }
  214.  
  215.   Address_1 = GfxMem + a1 * sizeof (*GfxMem);
  216.  
  217.   Address_2 = GfxMem + a2 * sizeof (*GfxMem);
  218.  
  219.   for (Var = (b1 + 1L); Var < b2; Var++)
  220.   {
  221.       if (Color != *(Address_1 + Var * MODULO_PPC)) return FALSE;
  222.  
  223.       if (Color != *(Address_2 + Var * MODULO_PPC)) return FALSE;
  224.   }
  225.  
  226.   return TRUE;
  227. }
  228.  
  229. BOOL RectangleDrawPPC (struct MandelChunk *MandelInfo,UBYTE *GfxMem,const LONG a1,const LONG b1,const LONG a2,const LONG b2)
  230. {
  231. REGISTER LONG helpx,helpy;
  232.  
  233. UBYTE filler;
  234.  
  235. UBYTE *Address;
  236.  
  237.   if ((helpx = (a2 - a1)) < MINLIMIT) return FALSE;
  238.  
  239.   if ((helpy = (b2 - b1)) < MINLIMIT) return FALSE;
  240.  
  241.   if (CheckBoxPPC (GfxMem,a1,b1,a2,b2))
  242.   {
  243.      filler = *(GfxMem + b1 * MODULO_PPC + a1 * sizeof (*GfxMem));
  244.  
  245.      for (helpy = b1; helpy <= b2; helpy++)
  246.      {
  247.         Address = GfxMem + (helpy * MODULO_PPC) + a1;
  248.  
  249.         for (helpx = a2; helpx >= a1; helpx--) *Address++ = filler;
  250.      }
  251.  
  252.      return FALSE;
  253.   }
  254.  
  255.   if ((helpx < (MINLIMIT * 2L)) || (helpy < (MINLIMIT * 2L)))
  256.   {
  257.      for (helpx = (a1 + 1L); helpx < a2; helpx++)
  258.      {
  259.          (*V_LINE_PPC) (MandelInfo,GfxMem,b1+1L,b2-1L,helpx);
  260.      }
  261.  
  262.      return FALSE;
  263.   }
  264.  
  265.   if (helpx >= helpy)
  266.   {
  267.      helpx = (a1 + a2) / 2;
  268.  
  269.      (*V_LINE_PPC) (MandelInfo,GfxMem,b1+1L,b2-1L,helpx);
  270.  
  271.      if (RectangleDrawPPC (MandelInfo,GfxMem,a1,b1,helpx,b2)) return TRUE;
  272.  
  273.      if (RectangleDrawPPC (MandelInfo,GfxMem,helpx,b1,a2,b2)) return TRUE;
  274.   }
  275.  
  276.   else
  277.   {
  278.      helpy = (b1 + b2) / 2;
  279.  
  280.      (*H_LINE_PPC) (MandelInfo,GfxMem,a1+1L,a2-1,helpy);
  281.  
  282.      if (RectangleDrawPPC (MandelInfo,GfxMem,a1,b1,a2,helpy)) return TRUE;
  283.  
  284.      if (RectangleDrawPPC (MandelInfo,GfxMem,a1,helpy,a2,b2)) return TRUE;
  285.   }
  286.  
  287.   return FALSE;
  288. }
  289.  
  290. void SAVEDS CalcFractalPPC (struct MandelChunk *MandelInfo,UBYTE *GfxMem)
  291. {
  292.  if (MandelInfo->Flags & JULIA_BIT)
  293.  {
  294.     H_LINE_PPC = JHLinePPC;
  295.  
  296.     V_LINE_PPC = JVLinePPC;
  297.  }
  298.  
  299.  else if (MandelInfo->Flags & MANDEL_BIT)
  300.  {
  301.     H_LINE_PPC = MHLinePPC;
  302.  
  303.     V_LINE_PPC = MVLinePPC;
  304.  }
  305.  
  306.  if (MandelInfo->Flags & LINEAR_BIT) COLORREMAP_PPC = LinearRemapPPC;
  307.  
  308.  else if (MandelInfo->Flags & LOG_BIT) COLORREMAP_PPC = LogRemapPPC;
  309.  
  310.       else if (MandelInfo->Flags & REPEATED_BIT) COLORREMAP_PPC = RepeatedRemapPPC;
  311.  
  312.            else if (MandelInfo->Flags & SQUARE_BIT) COLORREMAP_PPC = SquareRootRemapPPC;
  313.  
  314.                 else if (MandelInfo->Flags & ONE_BIT) COLORREMAP_PPC = OneRemapPPC;
  315.  
  316.                      else if (MandelInfo->Flags & TWO_BIT) COLORREMAP_PPC = TwoRemapPPC;
  317.  
  318.                           else if (MandelInfo->Flags & THREE_BIT) COLORREMAP_PPC = ThreeRemapPPC;
  319.  
  320.                                else if (MandelInfo->Flags & FOUR_BIT) COLORREMAP_PPC = FourRemapPPC;
  321.  
  322.  MODULO_PPC = MandelInfo->Modulo;
  323.  
  324.  COLORS_PPC = MandelInfo->Colors;
  325.  
  326.  INCREMIMAGPPC = (fabs (MandelInfo->IMax - MandelInfo->IMin)) / ((LDouble) (MandelInfo->Height - MandelInfo->TopEdge + 1));
  327.  
  328.  ITERATIONS_PPC = MandelInfo->Iterations;
  329.  
  330.  INCREMREALPPC = (fabs (MandelInfo->RMax - MandelInfo->RMin)) / ((LDouble) (MandelInfo->Width - MandelInfo->LeftEdge + 1));
  331.  
  332.  (*H_LINE_PPC) (MandelInfo,GfxMem,MandelInfo->LeftEdge,MandelInfo->Width,MandelInfo->TopEdge);
  333.  
  334.  (*V_LINE_PPC) (MandelInfo,GfxMem,MandelInfo->TopEdge+1,MandelInfo->Height-1,MandelInfo->LeftEdge);
  335.  
  336.  (*H_LINE_PPC) (MandelInfo,GfxMem,MandelInfo->LeftEdge,MandelInfo->Width,MandelInfo->Height);
  337.  
  338.  (*V_LINE_PPC) (MandelInfo,GfxMem,MandelInfo->TopEdge+1,MandelInfo->Height-1,MandelInfo->Width);
  339.  
  340.  RectangleDrawPPC (MandelInfo,GfxMem,MandelInfo->LeftEdge,MandelInfo->TopEdge,MandelInfo->Width,MandelInfo->Height);
  341. }